package com.siki.www.clock.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.siki.salessystemcommon.entity.City;
import com.siki.salessystemcommon.mapper.CityMapper;
import com.siki.salessystemcommon.mapper.ProvincesMapper;
import com.siki.www.clock.service.CityService;
import com.siki.www.clock.vo.CityInfoVO;
import com.siki.www.clock.vo.ProvincesAllInfoVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author qizai
 */

@Service
public class CityServiceImpl implements CityService {
    private final ProvincesMapper provincesMapper;
    private final CityMapper cityMapper;

    public CityServiceImpl(ProvincesMapper provincesMapper, CityMapper cityMapper) {
        this.provincesMapper = provincesMapper;
        this.cityMapper = cityMapper;
    }

    /**
     * 获得所有省份
     * @return
     */
    @Override
    public List<ProvincesAllInfoVO> getProvincesAll(){
        return provincesMapper.selectList(null)
                .stream().map(ProvincesAllInfoVO::new).collect(Collectors.toList());
    }

    @Override
    public List<CityInfoVO> getCityByProvincesId(Long provincesId) {
        return cityMapper.selectList(new QueryWrapper<City>().eq("province_id",provincesId))
                .stream().map(CityInfoVO::new).collect(Collectors.toList());
    }
}
